package cn.itcast.demo.service;

import cn.itcast.demo.mapper.UserMapper;
import cn.itcast.demo.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: taft
 * @Date: 2018-12-6 11:53
 */
@Service
public class UserService {

    @Autowired
    private UserMapper userMapper;

    Logger logger = LoggerFactory.getLogger(UserService.class);


    public User queryUserById(Long id) {

        long startTime = System.currentTimeMillis();
        int time = (int) (Math.random()*2000+1);//1 - 2000

        try {
            Thread.sleep(time);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        User user = userMapper.selectByPrimaryKey(id);

        long endTime = System.currentTimeMillis();

        logger.info("本次查询:{},花费时间为:{}ms",id,endTime-startTime);
        return user;
    }

    @Transactional
    public void deleteUserById(Long id){
        //this.userMapper.deleteUserById(id);
    }
}
